package com.cy.ppj.web.admin.netpoint;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cy.ppj.model.PageBean;
import com.cy.ppj.model.Result;
import com.cy.ppj.model.ao.netpoint.NetPointAddAO;
import com.cy.ppj.model.ao.netpoint.NetPointEditAO;
import com.cy.ppj.model.domian.netpoint.NetPoint;
import com.cy.ppj.model.query.netpoint.NetPointAdminQuery;
import com.cy.ppj.model.vo.admin.netpoint.NetPointAdminVO;
import com.cy.ppj.service.netpoint.NetPointService;
import com.cy.ppj.web.BaseController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;

/**
 * 后台-网点管理
 *
 * @author: tanyilin
 * @create: 2018年10月12日 下午5:30:40
 */
@Slf4j
@RestController
@RequestMapping("/admin/net/point")
@Api(tags = "后台-网点管理")
public class AdminNetPointController extends BaseController{

	@Autowired
	private NetPointService netPointService;
	
	@ApiOperation("网点列表")
	@GetMapping("/list")
	public PageBean<NetPointAdminVO> list(NetPointAdminQuery query) {
		PageBean<NetPointAdminVO> pageBean = netPointService.selectNetPointAdminList(query);
		return pageBean;
	}
	
	@ApiOperation("新增")
	@PostMapping("/do/add")
	public Result doAdd(@Validated NetPointAddAO netPointAddAO, BindingResult bindingResult) {
		this.checkError(bindingResult);
		NetPoint netPoint = new NetPoint();
		BeanUtils.copyProperties(netPointAddAO, netPoint);
		netPointService.addNetPoint(netPoint);
		return ok();
	}
	
	@ApiOperation("编辑")
	@PostMapping("/do/edit")
	public Result doEdit(@Validated NetPointEditAO netPointEditAO, BindingResult bindingResult) {
		this.checkError(bindingResult);
		NetPoint netPoint = new NetPoint();
		BeanUtils.copyProperties(netPointEditAO, netPoint);
		netPointService.updateNetPoint(netPoint);
		return ok();
	}
	
	@ApiOperation("删除")
	@PostMapping("/do/delete")
	public Result doDelete(@ApiParam(value = "ID", example = "0", required = true) @RequestParam Long id) {
		NetPoint netPoint = new NetPoint();
		netPoint.setId(id);
		netPointService.deleteNetPoint(netPoint);
		return ok();
	}
	
}
